<?php 
/*****************
*模板调用具体广告接口
*创建日期:2012-4-13
*作者：tjx
******************/
header("expires:mon,26 jul 1997 05:00:00 gmt");  
header("cache-control:no-cache,must-revalidate");  
header("pragma:no-cache");
define('IN_WONDERSHARE', true);

if( $_GET['code'] != md5('ad') ) {
	exit('error code!');
}

require( '../../inc/config.inc.php');
require( '../../includes/cls_mysql.php');
require( '../../includes/lib_common.php');

if(empty($db)) {
	$db = new cls_mysql($db_host, $db_user, $db_pass, $db_name);
}

/**
* 函数名：getArticleRightAd($db)
* 描述：得到文章右侧广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleRightAd($db) {
	
	$str = '';
	$a_id = (int) $_GET['id'];//文章标识
	$web_type = (int) $_GET['web_type'];//网站标识
	
	$ad_prefix_html = '';
	$ad_suffix_html = '';
	switch ($web_type) {
		
		//wondershare 
		case 1:
	
			$position_id = 1;//广告位Id
			break;
		//daniusoft
		case 15:
	
			$position_id = 55;//广告位Id
			$ad_prefix_html = '<div class="rt_banner">';
			$ad_suffix_html = '</div>';
			break;
	
	}
	
	$sql = "SELECT `ar_cat_id` FROM topic_article WHERE `is_delete`=0 AND `ar_id`= {$a_id} ";
	$cat_id = $db->getOne($sql);
	
	if (!empty($cat_id)) {
		
		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id = '{$cat_id}' AND ad_delivery.position_type =1 
				AND ad_delivery.ad_web = {$web_type} AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
		$rows = $db->getOneRs($sql);
		
		if (!empty($rows)) {

			$row_size = explode('*',$rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = $ad_prefix_html.'<a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].'" width="'.
					$row_size[0].'" height="'.$row_size[1].'" /></a>'.$ad_suffix_html;
		}
		
		
	} 
	echo  $str;
	
}

/**
* 函数名：getArticleTopAd($db)
* 描述：得到文章头部广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleTopAd($db) {
	
	$str = '';
	$a_id = (int) $_GET['id'];//文章标识
	$web_type = (int) $_GET['web_type'];//网站标识
	switch ($web_type) {
		
		//wondershare 
		case 1:
	
			$position_id = 4;//广告位Id
			break;
		//daniusoft
		case 15:
	
			$position_id = 54;//广告位Id
			break;
	
	}
	
	$sql="SELECT `ar_cat_id` FROM topic_article WHERE `is_delete`=0 AND `ar_id`= {$a_id} ";
	$cat_id = $db->getOne($sql);
	
	if (!empty($cat_id)) {
		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id = '{$cat_id}' AND ad_delivery.position_type =1 
				AND ad_delivery.ad_web = {$web_type} AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
		$rows = $db->getOneRs($sql);
		
		if (!empty($rows)) {
			$row_size = explode('*',$rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			$str = '<div class="topbanner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].
					'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
		}
		
		
		
	} 
	echo  $str;
	
	
}

/**
* 函数名：getArticleResourceRightAd($db)
* 描述：得到文章聚合页右侧部广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleResourceRightAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	switch ($web_type) {
		
		//wondershare 
		case 1:
			$position_id = 5;//广告位Id
			break;
	
	}
	$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
			FROM ad_delivery, ad, ad_position 
			WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id = 0 AND ad_delivery.position_type =2 
			AND ad_delivery.ad_web = {$web_type} AND ad_position.position_id = ad_delivery.position_id 
			AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
	
	$rows = $db->getOneRs($sql);
	
	if (!empty($rows)) {
		
		$row_size = explode('*',$rows['position_size']);
		$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
		$str = '<a href="'.$ad_url.'">
				<img src="http://wondershare.go2cloud.org/aff_i?offer_id=19&aff_id=1035" width="1" height="1"><img src="'.
				$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a>';
	
	}
	
	echo  $str;

	
	
	
}

/**
* 函数名：getArticleResourceTopAd($db)
* 描述：得到文章聚合页头部广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleResourceTopAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	switch ($web_type) {
		
		//wondershare 
		case 1:
	
			$position_id = 6;//广告位Id
			break;
		//daniusoft
		case 15:
	
			$position_id = 53;//广告位Id
			break;
	
	}
	$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
			FROM ad_delivery, ad, ad_position 
			WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id = 0 AND ad_delivery.position_type = 2 
			AND ad_delivery.ad_web = {$web_type} AND ad_position.position_id = ad_delivery.position_id 
			AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
	$rows = $db->getOneRs($sql);
	
	if (!empty($rows)) {
		
		$row_size = explode('*', $rows['position_size']);
		$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
		$str = '<div class="topbanner"><a href="'.$ad_url.'">
				<img src="'.$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
	}
	echo  $str;
	
	
	
}


/**
* 函数名：getArticleTagRightAd($db)
* 描述：得到文章标签右侧部广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleTagRightAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	$ad_prefix_html = '';
	$ad_suffix_html = '';
	switch ($web_type) {
		
		//wondershare 
		case 1:
			$position_id = 2;//广告位Id
			break;
		//daniusoft
		case 15:
	
			$position_id = 57;//广告位Id
			$ad_prefix_html = '<div class="rt_banner">';
			$ad_suffix_html = '</div>';
			break;
	
	}
	
	$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
			FROM ad_delivery, ad, ad_position 
			WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id =0 AND ad_delivery.position_type =4 
			AND ad_delivery.ad_web = '{$web_type}' AND ad_position.position_id = ad_delivery.position_id 
			AND ad_delivery.ad_id = ad.ad_id LIMIT 1";

	$rows = $db->getOneRs($sql);
	
	if (!empty($rows)) {
		$row_size = explode('*', $rows['position_size']);
		$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
		$str = $ad_prefix_html.'<a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].'" width="'.
		$row_size[0].'" height="'.$row_size[1].'" /></a>'.$ad_suffix_html;
	}
	echo  $str;
	

	
	
	
}

/**
* 函数名：getArticleTagTopAd($db)
* 描述：得到文章标签头部广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleTagTopAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	switch ($web_type) {
		
		//wondershare 
		case 1:
	
			$position_id = 26;//广告位Id
			break;
		//daniusoft
		case 15:
	
			$position_id = 56;//广告位Id
			break;
	
	}
	
	$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
			FROM ad_delivery, ad, ad_position 
			WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id = 0 AND ad_delivery.position_type =4 
			AND ad_delivery.ad_web = '{$web_type}' AND ad_position.position_id = ad_delivery.position_id 
			AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
	
	$rows = $db->getOneRs($sql);
	
	if (!empty($rows)) {
		
		$row_size = explode('*',$rows['position_size']);
		$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
		$str = '<div class="topbanner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
	}
	echo $str;
	
	
	
}

/**
* 函数名：getArticleCategoryRightAd($db)
* 描述：得到分类右侧部广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleCategoryRightAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	$cat_id =  (int) $_GET['id'] ;//分类id
	$ad_prefix_html = '';
	$ad_suffix_html = '';
	
	switch ($web_type) {
		
		//wondershare 
		case 1:
			$position_id = 1;//广告位Id
			break;
			
	   //daniusoft
		case 15:
			$position_id = 55;//广告位Id
			$ad_prefix_html = '<div class="rt_banner">';
			$ad_suffix_html = '</div>';
			break;
	
	}

	$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
			FROM ad_delivery, ad, ad_position 
			WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id = {$cat_id} AND ad_delivery.position_type =1 
			AND ad_delivery.ad_web = {$web_type} AND ad_position.position_id = ad_delivery.position_id 
			AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
	$rows = $db->getOneRs($sql);
	
	if (!empty($rows)) {
		$row_size = explode('*', $rows['position_size']);
		$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
		$str = $ad_prefix_html.'<a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   alt="'.$rows['ad_alt'].'" width="'.
		$row_size[0].'" height="'.$row_size[1].'" /></a>'.$ad_prefix_html;
	}
	echo  $str;
	
	
	
}

/**
* 函数名：getArticleCategoryTopAd($db)
* 描述：得到分类头部广告
* @params $db 操作数据库对象
* @return  int
*/
function getArticleCategoryTopAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	$cat_id =  (int) $_GET['id'] ;//分类id
	switch ($web_type) {
		
		//wondershare 
		case 1:
	
			$position_id = 4;//广告位Id
			break;
		//daniusoft
		case 15:
			$position_id = 54;//广告位Id
			break;
	
	}

	$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
			FROM ad_delivery, ad, ad_position 
			WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.cat_id = {$cat_id} 
			AND ad_delivery.position_type =1 AND ad_delivery.ad_web = {$web_type} 
			AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
	
	$rows = $db->getOneRs($sql);
	
	if (!empty($rows)) {
		$row_size = explode('*', $rows['position_size']);
		$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
		$str = '<div class="topbanner"><a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   alt="'.
		$rows['ad_alt'].'" width="'.$row_size[0].'" height="'.$row_size[1].'" /></a></div>';
	}
	
	echo  $str;
	
	
	
	
}

/**
* 函数名：getProductsRightAd($db)
* 描述：得到产品右侧广告
* @params $db 操作数据库对象
* @return  int
*/
function getProductsRightAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	$id =  (int) $_GET['id'] ;//分类id
	switch ($web_type) {
		
		//wondershare 
		case 1:
	
			$position_id = 7;//广告位Id
			break;
	
	}
	$sql = "SELECT cat.parent_path 
			FROM won_product won_p 
			LEFT JOIN category cat ON won_p.cat_id = cat.cat_id 
			WHERE won_p.id = {$id}";
	$parent_path = $db->getOne($sql);
	
	$row = explode(',', $parent_path);
	$father_cat_id = $row[0];//得到一级分类id
	
	if (!empty($father_cat_id)) {
		
		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id = '{$position_id}' AND ad_delivery.ws_id = {$id} AND ad_delivery.cat_id = '{$father_cat_id}' 
				AND ad_delivery.position_type =5 AND ad_delivery.ad_web = '{$web_type}' AND ad_delivery.is_text_ad = 0 
				AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
		$rows = $db->getOneRs($sql);
		
		if (!empty($rows)) {
			$row_size = explode('*', $rows['position_size']);
			$ad_url = $rows['ad_url'].'?icn='.$rows['ad_name'].'&ici='.$rows['position_name'];
			
			$str = '<a href="'.$ad_url.'"><img src="'.$rows['ad_photo'].'"   alt="'.
					$rows['ad_alt'].'" width="'.$row_size.'" height="'.$row_size[1].'" /></a>';
		}
	}
	echo $str;
}

/**
* 函数名：getProductsTextAd($db)
* 描述：得到产品文字广告
* @params $db 操作数据库对象
* @return  int
*/
function getProductsTextAd($db) {
	
	$str = '';
	$web_type = (int) $_GET['web_type'];//网站标识
	$id =  (int) $_GET['id'] ;//分类id
		
	$sql = "SELECT ad.ad_url,ad.ad_content 
			FROM ad_delivery ad_d 
			LEFT JOIN ad ad ON ad.ad_id = ad_d.ad_id 
			WHERE ad_d.ws_id = {$id} AND ad_d.ad_web = '{$web_type}' AND ad_d.is_text_ad = 1 AND ad.is_delete = 0 LIMIT 1 ";
	$rows = $db->getOneRs($sql);
	
	if (!empty($rows)) {
		
	  $str = '<p class="promotext"><a href="'.$rows['ad_url'].'">'.$rows['ad_content'].' >></a></p>';
	}
	echo  $str;
}


$fun = $_GET['fun'];
$fun($db);
?>